package io.renren.controller;

import io.renren.annotation.Login;
import io.renren.annotation.LoginUser;
import io.renren.common.utils.R;
import io.renren.entity.StudentEntity;
import io.renren.service.SignUpPaymentLogService;
import io.renren.service.StudentService;
import io.renren.util.ApiBaseAction;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/student")
public class ApiStudentController extends ApiBaseAction {

    @Autowired
    private StudentService studentService;
    @Autowired
    private SignUpPaymentLogService signUpPaymentLogService;

    @Login
    @PostMapping("getRelatedSchool")
    @ApiOperation("关联学校")
    public R getRelatedSchool(@LoginUser StudentEntity student){
        return studentService.getRelatedSchool(student);
    }

    /**
     * 获取学员信息
     *
     * @param student 学员
     * @return R
     */
    @Login
    @PostMapping("getStudentInfo")
    @ApiOperation("获取学员信息")
    public R getStudentInfo(@LoginUser StudentEntity student) {
        return studentService.getStudentInfo(student);
    }


    /***
     *小程序
     * 获取一键报名科目id
     * @param type 科目类别:1人社 2交通 3安监
     * @param subjectName 科目名称
     * @return
     */
    @PostMapping("getSignUpSubjectId")
    @ApiOperation("获取一键报名科目id")
    public R signUpRecord(@RequestParam Integer type,
                          String subjectName) {
        return studentService.getSignUpSubjectId(type, subjectName);
    }


    /**
     * 小程序
     * 一键报名
     *
     * @param realName        真实姓名
     * @param phone           手机号码
     * @param idCard          身份证
     * @param signUpSubjectId 科目id
     * @return R
     */
    @PostMapping("signUpRecord")
    @ApiOperation("一键报名")
    public R signUpRecord(@RequestParam("realName") String realName,
                          @RequestParam("phone") String phone,
                          @RequestParam("idCard") String idCard,
                          @RequestParam("signUpSubjectId") Integer signUpSubjectId) {
        return studentService.signUpRecord(realName, phone, idCard, signUpSubjectId);
    }


    /***
     * 小程序
     * 获取证件信息
     * @param student 学员
     * @return
     */
    @Login
    @PostMapping("getCertificate")
    @ApiOperation("获取证件信息")
    public R getCertificate(@LoginUser StudentEntity student) {
        return studentService.getCertificate(student);
    }

    /***
     * 小程序
     * 修改个人中心信息
     * @param student 学员
     * @param imgUrl 头像
     * @param realName 真实姓名
     * @param phone 电话
     * @param idCard 身份证
     * @param userName 昵称
     * @param sex 性别 1男 2女 3保密
     * @return
     */
    @Login
    @PostMapping("setCenterInfo")
    @ApiOperation("修改个人中心")
    public R setCenterInfo(@LoginUser StudentEntity student,
                           String imgUrl,
                           String realName,
                           String phone,
                           String idCard,
                           String userName,
                           Integer sex) {
        return studentService.setCenterInfo(student, imgUrl, realName, phone, idCard, userName, sex);
    }

    /***
     * 获取个人中心信息
     * @param student 学生
     * @return R
     */
    @Login
    @PostMapping("getCenterInfo")
    @ApiOperation("获取个人中心")
    public R getCenterInfo(@LoginUser StudentEntity student) {
        return studentService.getCenterInfo(student);
    }


    /***
     * 小程序
     * 获取我的订单
     * @param student 学员
     * @return R
     */
    @Login
    @PostMapping("getOrderList")
    @ApiOperation("我的订单")
    public R getOrderList(@LoginUser StudentEntity student) {
        return studentService.getOrderList(student);
    }


    /***
     * 小程序
     * 评论科目
     * @param student 学员
     * @param teachStar 教学星
     * @param envStar 环境星
     * @param payStar 收费星
     * @param serverStar 服务星
     * @param contentDesc 文字
     * @param isName 是否匿名 0不用匿名 1要匿名
     * @param paymentLogId 订单id
     * @param imageUrl 图片
     * @return R
     */
    @Login
    @PostMapping("evaluateSubject")
    @ApiOperation("评论科目")
    public R evaluateSubject(@LoginUser StudentEntity student,
                             @RequestParam("teachStar") float teachStar,
                             @RequestParam("envStar") float envStar,
                             @RequestParam("payStar") float payStar,
                             @RequestParam("serverStar") float serverStar,
                             String contentDesc,
                             @RequestParam("isName") Integer isName,
                             Integer paymentLogId,
                             String imageUrl) {
        return signUpPaymentLogService.evaluateSubject(student, teachStar, envStar, payStar, serverStar, contentDesc, isName, paymentLogId, imageUrl);
    }


}
